package cn.ssh.service.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import cn.ssh.dao.CommonDao;
import cn.ssh.entity.SaleOrder;
import cn.ssh.entity.SaleOrderLine;
import cn.ssh.service.OrderService;

@Service("orderService")
public class OrderServiceImpl implements OrderService {

	@Autowired
	@Qualifier("commonDao")
	private CommonDao commonDao = null;

	public CommonDao getCommonDao() {
		return commonDao;
	}

	public void setCommonDao(CommonDao commonDao) {
		this.commonDao = commonDao;
	}

	@Override
	public void add(SaleOrder saleOrder) {
		// TODO Auto-generated method stub
		this.commonDao.add(saleOrder);

	}

	@Override
	public SaleOrder get(Serializable id) {
		// TODO Auto-generated method stub
		SaleOrder ret = (SaleOrder) this.commonDao.get(SaleOrder.class, id);
		return ret;
	}

	@Override
	public SaleOrder getWithLines(Serializable id) {
		SaleOrder ret = null;
		String hql = "select o from SaleOrder o left join fetch " + "o.saleOrderLines where o.odrId=" + id;
		List list = this.commonDao.search(hql);
		if (null != list && !list.isEmpty()) {
			ret = (SaleOrder) list.get(0);
		}
		return ret;
	}

	@Override
	public void addDetail(SaleOrderLine orderDetail) {
		// TODO Auto-generated method stub
		this.commonDao.add(orderDetail);

	}

}
